
<?php
include("db/connect.php");
include("funcsubstr.php");
$sqlselectmaterial="select * from material,cartmaterial,ordersmaterial where material.mat_id=cartmaterial.mat_id and ordersmaterial.ordermat_id=cartmaterial.ordermat_id and ordersmat_status='111'";
//echo $sqlselectmaterial;
//$sqlselectmaterial.=" mat_id like '%".$_POST["txtsearch"]."%' group by mat_id";
$queryselectmaterial=mysql_query($sqlselectmaterial);
?>
<div>
<div>ประเภท <select id="statusmat" name="statusmat">
<option value="111">อนุมัติแล้ว</option>
<option value="000">รออนุมัติ</option>
<option value="222">ยกเลิกการขอ</option>
</select></div>

<div>ค้นจากชื่อวัตถุดิบ <input type="text" id="namemat" name="namemat" /> <input type="button" id="btnorder" onClick="genMaterial();" value="ค้นหา" /></div>
</div>
<div id="divmat">
  <table width="100%" border="1">
    <tr>
      <th width="138">รหัสการสั่งซื้อวัตถุดิบ</th>
      <th width="68">วันที่สั่งซื้อ</th>
      <th width="101">ชื่อวัตถุดิบ</th>
      <th width="50">ราคา(บาท)</th>
      <th width="80">จำนวน(หน่วย)</th>
      <th width="66">ยอดรวม</th>
   
    </tr>
<?php 
  while($resultmaterial=mysql_fetch_array($queryselectmaterial)){
	   $year=substr($resultmaterial["ordersmat_date"],0,4)+543;
		$month=monthconv(substr($resultmaterial["ordersmat_date"],5,2));
		$day=substr($resultmaterial["ordersmat_date"],8,2);
  ?>
    <tr>
      <td><?php echo $resultmaterial["ordermat_id"]?></td>
      <td><?php echo $day.' '.$month.' '.$year?></td>
      <td><?php echo $resultmaterial["mat_name"]?></td>
      <td><?php echo $resultmaterial["mat_price"]?></td>
      <td><?php echo ($resultmaterial["mat_qty"]."  ".$resultmaterial["mat_unit"])?></td>
      <td><?php echo number_format ($resultmaterial["mat_price"]*$resultmaterial["mat_qty"])?></td>

    </tr>
    <?php }?>
  </table>
  </div>
  <script>
  function  materialUpdate(type,id){
	  switch (type){
		  
		  case 1: if(window.confirm("ต้องการยืนยันใช่ไหม")){
		  			$.ajax({url:"update_material.php?mode=1&status=111&orderid="+id,
					success: function(msg){
						genMaterial();
						}
					});}
		  		break;		 
		 case 2: if(window.confirm("ต้องการยกเลิกใช่ไหม"))
		  			{$.ajax({url:"update_material.php?mode=2&status=222&orderid="+id,
						type:"GET",
					success: function(){
						genMaterial();
						}
					
					});}
		  		break;		 
				
 
 }
	  }
	  
	  function genMaterial(){
		  $.ajax({url:"update_material.php?mode=3&status="+$("#statusmat").val()+"&namemat="+$("#namemat").val(),
					success: function(msg){
						$("#divmat").html(msg);
						}
					
					});
		  }
  </script>

